<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>100内偶数的和</title>
</head>

<body>
    <script>
        // 计算1-100偶数和，和到达2000时输出；
        var sum = 0;
        for (var i = 1; i <= 100; i++) {
            if (i % 2 == 0) {//判断i是否为偶数
                sum = sum + i;
                if (sum > 2000) {
                    document.write("i=" + i + "<br />");
                    break;
                }
            }
        }
        document.write("sum=" + sum + "<br />");
    </script>
</body>

</html>